1. Field of the Invention
This invention relates to a counter circuit, and particularly to a circuit for detecting the direction in which a counter is counting, i.e., whether the counter is counting up or down.
2. Description of the Related Art
As the demand for an improved speed and efficiency of the control technology of microcomputers increases, many functions now carried out by software are being gradually replaced with hardware.
For example, a counter serving as a peripheral circuit of a microcomputer for controlling the position of a motor will be explained. To identify the direction of rotation of the motor (a moving object), a CPU of the microcomputer refers to count data provided by the counter, and whenever this directional information is needed, the CPU issues an interrupt request to obtain the count data, and processes the obtained count data. In this case, the CPU must sample the count data at least twice and calculate a difference in the sampled data to detect the direction of movement of the moving object (the motor). This technique imposes a heavy load on the software of the CPU, thereby hindering the execution by the CPU of other programs, and thus extending the period needed for identifying the direction of movement the moving object.
FIG. 1 shows a conventional up/down counter, and the operation and arrangement of this counter will be explained with reference thereto. The up/down counter 100 is used for controlling, for example, the position of a motor, and comprises an edge detector 1 and a 4-bit counter 2.
The edge detector 1 includes a down-edge detector 1A, an up-edge detector 1B, an exclusive or logic circuit N11, and an AND logic circuit A11.
The 4-bit counter 2 includes four T-type flip-flops TF1 to TF4 connected to a bus line (not shown), inverters IN21 to IN23, AND logic circuits A21 to A28, and OR logic circuits O21 to O23, in which the inverters and AND and OR logic circuits serve as carry bit detecting elements.
FIG. 2 is a time chart showing the function of the up/down counter 100. The up/down counter 100 detects an up indication signal SU2 or a down indication signal SD2 according to a reference clock signal CLK and an up signal SU or a down signal SD, provides a count clock signal CK in response to the detected signal SU2 or SD2, and according to the count clock signal CK, provides 4-bit count data QC0 to QC3 with which a CPU (not shown) controls the position of the motor.
According to this conventional technique, the CPU must rely on software to determine whether the up/down counter 100 is counting up or down, when identifying the direction of rotation of the motor, and this process takes a long time because the CPU must monitor changes in the count data for a predetermined period, and sample at least two data. This imposes a heavy load on the software of the CPU and thus hinders the execution of other programs thereby.
Whenever a motor position control system requests an identification of the direction of rotation of the motor, the CPU issues an interrupt request to process the count data QC0 to QC3 provided by the up/down counter 100. For example, the CPU samples the count data twice at an optional timing and finds a difference between the sampled data. If the difference X is X&lt;0, the CPU determines that the direction of the normal direction, and if X&gt;0, determines that the direction of the counter is downward, i.e., the motor is rotating in a reverse direction.
Referring to the time chart of FIG. 2, when the 4-bit counter 2 receives the count clock signal CK while the up indication signal SU2 is ON, the count data QC0 to QC3 will be 1, 0, 0, and 0, respectively, and this state is held until the 4-bit counter 2 receives the next down indication signal SD2. In response to reception of the down indication signal SD2, the count data QC0 to QC3 become 0, 1, 1, and 1, respectively. To find the direction of movement of the moving object (the motor), the CPU issues interrupt requests to sample the count data QC0 to QC3 at at least two different temporal points. If the count data at each sampling point is 1, 0, 0, and 0, the CPU determines that the moving object is moving in a count-up direction, and if the data of each sampling point is 0, 1, 1, and 1, it is moving in a count-down direction. With this kind of detection method using software, it takes a long time to identify the direction of movement, which lowers the speed of the control of the moving object and does not allow a reduction of the size of a control program.
Therefore, there is a demand for a counter circuit using hardware to detect a count-up signal or a count-down signal indicating the direction of movement of a moving object, and to instantaneously provide a CPU with the direction of movement information as and when requested, to thus reduce the load on the software of the CPU.